//------------------------------------------------------------------------------
// X2TK Graphic Toolkit
// Copyright (C) 2006-2008 Janusz Kowalski
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------

#ifndef X2TK_BUTTON_H
#define X2TK_BUTTON_H

#include "x2tk_Widget.h"

namespace x2tk {

// Simple button widget. When clicked, it returns ActionId assigned to it.
class Button : public Widget {
  private:
    Font font_;
    bool isPressed;
    bool isHovered;
    const char *labelText;
    int defaultActionId;
    // Image of the button.
    SDL_Surface *image;
    // Image of the pressed button.
    SDL_Surface *imagePressed;
    SDL_Surface *imageFocus;
    bool changed;
    
    Image texNormal;
    Image texPressed;
  public:
    // Create button with the given label and positions.
    Button(int x, int y, int w, int h, const char *label);
    
    // Create button. Dimensions of the button are set automatically depending
    // on the label size.
    Button(const char *label, int defaultActionId=0);
    
    ~Button();
    
    virtual void resize(int w, int h);
    
    virtual void draw(GraphicContext &g);
    bool mouseDown(int type);
    void mouseUp(int type);
    void mouseMove(int x, int y);
    
    void setAction(int action);
    
    virtual void event_key(const SDL_KeyboardEvent& key);
    
    virtual void timed(int id);
};

} // namespace x2tk

#endif
